from django.db import models
from django.contrib.auth.models import User
from public.models import CommonInfo
from envx.models import Env
from appinput.models import App


class Action(CommonInfo):
    """权限行为"""
    aid = models.IntegerField(unique=True, verbose_name="权限序号")


class Permission(CommonInfo):
    """权限"""
    app_name = models.ForeignKey(App, on_delete=models.CASCADE, related_name="pm_app_name", verbose_name="APP应用")
    env_name = models.ForeignKey(Env, on_delete=models.CASCADE, related_name="pm_env_name",
                                 blank=True, null=True, verbose_name="环境")
    action_name = models.ForeignKey(Action, on_delete=models.CASCADE, related_name="pm_action_name",
                                    verbose_name="操作权限")
    main_user = models.ManyToManyField(User, related_name="pm_user", blank=True, verbose_name="操作用户")
